Chromium Code Reviews| 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 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 if (is_generator()) { | 1616 if (is_generator()) { |
| 1617 return_value = BuildIteratorResult(return_value, true); | 1617 return_value = BuildIteratorResult(return_value, true); |
| 1618 } else if (is_async_function()) { | 1618 } else if (is_async_function()) { |
| 1619 return_value = BuildResolvePromise(return_value, return_value->position()); | 1619 // In an async function, |
| 1620 // return expr; | |
| 1621 // is rewritten as | |
| 1622 // return .async_return_value = expr, undefined; | |
|
neis
2017/02/08 10:28:41
Why bother returning undefined? You can just do
gsathya
2017/02/09 00:55:44
Yeah it doesn't matter; the returned value is thro
| |
| 1623 Assignment* set_async_return_var = factory()->NewAssignment( | |
| 1624 Token::INIT, factory()->NewVariableProxy(AsyncReturnVariable()), | |
| 1625 return_value, kNoSourcePosition); | |
|
neis
2017/02/08 10:28:41
This must be ASSIGN, not INIT.
gsathya
2017/02/09 00:55:44
Done.
| |
| 1626 | |
| 1627 return_value = factory()->NewBinaryOperation( | |
| 1628 Token::COMMA, set_async_return_var, | |
| 1629 factory()->NewUndefinedLiteral(kNoSourcePosition), | |
| 1630 return_value->position()); | |
| 1620 } | 1631 } |
| 1621 return return_value; | 1632 return return_value; |
| 1622 } | 1633 } |
| 1623 | 1634 |
| 1624 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { | 1635 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { |
| 1625 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 1636 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
| 1626 DoExpression* expr = factory()->NewDoExpression(body, result, pos); | 1637 DoExpression* expr = factory()->NewDoExpression(body, result, pos); |
| 1627 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 1638 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
| 1628 *ok = false; | 1639 *ok = false; |
| 1629 return nullptr; | 1640 return nullptr; |
| (...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2970 if (param_scope != nullptr) { | 2981 if (param_scope != nullptr) { |
| 2971 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 2982 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
| 2972 } | 2983 } |
| 2973 init_block->statements()->Add(param_block, zone()); | 2984 init_block->statements()->Add(param_block, zone()); |
| 2974 } | 2985 } |
| 2975 ++index; | 2986 ++index; |
| 2976 } | 2987 } |
| 2977 return init_block; | 2988 return init_block; |
| 2978 } | 2989 } |
| 2979 | 2990 |
| 2991 Block* Parser::BuildRejectPromiseOnExceptionForParameters(Block* inner_block) { | |
| 2992 return BuildRejectPromiseOnException(inner_block, true); | |
| 2993 } | |
| 2994 | |
| 2980 Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { | 2995 Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { |
| 2996 return BuildRejectPromiseOnException(inner_block, false); | |
| 2997 } | |
| 2998 | |
| 2999 Block* Parser::BuildRejectPromiseOnException(Block* inner_block, | |
| 3000 bool is_parameter_block) { | |
| 2981 // .promise = %AsyncFunctionPromiseCreate(); | 3001 // .promise = %AsyncFunctionPromiseCreate(); |
| 3002 // .is_rejection = false; | |
| 2982 // try { | 3003 // try { |
| 2983 // <inner_block> | 3004 // <inner_block> |
| 2984 // } catch (.catch) { | 3005 // } catch (.catch) { |
| 2985 // %RejectPromise(.promise, .catch); | 3006 // .is_rejection = true; |
| 3007 // .async_return_value = .catch; | |
| 3008 // } finally { | |
| 3009 // .is_rejection ? %RejectPromise(.promise, .async_return_value) | |
| 3010 // : %ResolvePromise(.promise, .async_return_value); | |
|
caitp
2017/02/07 23:47:17
Given that the parameter-init-block doesn't need t
gsathya
2017/02/09 00:55:44
I agree, it is wasteful. I've split this into two
| |
| 3011 // %AsyncFunctionPromiseRelease(.promise); | |
| 2986 // return .promise; | 3012 // return .promise; |
| 2987 // } finally { | |
| 2988 // %AsyncFunctionPromiseRelease(.promise); | |
| 2989 // } | 3013 // } |
| 2990 Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); | 3014 Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); |
| 3015 Variable* is_rejection_var = | |
| 3016 scope()->NewTemporary(ast_value_factory()->empty_string()); | |
| 2991 | 3017 |
| 2992 // .promise = %AsyncFunctionPromiseCreate(); | 3018 // .promise = %AsyncFunctionPromiseCreate(); |
| 2993 Statement* set_promise; | 3019 // .is_rejection = false; |
| 2994 { | 3020 { |
| 3021 Statement* set_promise; | |
| 2995 Expression* create_promise = factory()->NewCallRuntime( | 3022 Expression* create_promise = factory()->NewCallRuntime( |
| 2996 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, | 3023 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, |
| 2997 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); | 3024 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); |
| 2998 Assignment* assign_promise = factory()->NewAssignment( | 3025 Assignment* assign_promise = factory()->NewAssignment( |
| 2999 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), | 3026 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), |
| 3000 create_promise, kNoSourcePosition); | 3027 create_promise, kNoSourcePosition); |
| 3001 set_promise = | 3028 set_promise = |
| 3002 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); | 3029 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); |
| 3030 result->statements()->Add(set_promise, zone()); | |
| 3031 | |
| 3032 Assignment* set_is_rejection = factory()->NewAssignment( | |
| 3033 Token::INIT, factory()->NewVariableProxy(is_rejection_var), | |
| 3034 factory()->NewBooleanLiteral(false, kNoSourcePosition), | |
| 3035 kNoSourcePosition); | |
| 3036 result->statements()->Add( | |
| 3037 factory()->NewExpressionStatement(set_is_rejection, kNoSourcePosition), | |
| 3038 zone()); | |
| 3003 } | 3039 } |
| 3004 result->statements()->Add(set_promise, zone()); | |
| 3005 | 3040 |
| 3006 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } | 3041 // catch (.catch) { |
| 3042 // .is_rejection = true; | |
| 3043 // .async_return_value = .catch; | |
| 3044 // } | |
| 3007 Scope* catch_scope = NewScope(CATCH_SCOPE); | 3045 Scope* catch_scope = NewScope(CATCH_SCOPE); |
| 3008 catch_scope->set_is_hidden(); | 3046 catch_scope->set_is_hidden(); |
| 3009 Variable* catch_variable = | 3047 Variable* catch_variable = |
| 3010 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); | 3048 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
| 3011 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3049 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3050 { | |
| 3051 Assignment* set_is_rejection = factory()->NewAssignment( | |
| 3052 Token::INIT, factory()->NewVariableProxy(is_rejection_var), | |
| 3053 factory()->NewBooleanLiteral(true, kNoSourcePosition), | |
| 3054 kNoSourcePosition); | |
|
neis
2017/02/08 10:28:41
This must be ASSIGN, not INIT.
gsathya
2017/02/09 00:55:45
Done.
| |
| 3012 | 3055 |
| 3013 Expression* promise_reject = BuildRejectPromise( | 3056 Assignment* set_async_return_var = factory()->NewAssignment( |
| 3014 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); | 3057 Token::INIT, factory()->NewVariableProxy(AsyncReturnVariable()), |
| 3015 ReturnStatement* return_promise_reject = | 3058 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
| 3016 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); | 3059 |
|
neis
2017/02/08 10:28:41
This must be ASSIGN, not INIT.
gsathya
2017/02/09 00:55:45
Done.
| |
| 3017 catch_block->statements()->Add(return_promise_reject, zone()); | 3060 catch_block->statements()->Add( |
| 3061 factory()->NewExpressionStatement(set_is_rejection, kNoSourcePosition), | |
| 3062 zone()); | |
| 3063 catch_block->statements()->Add(factory()->NewExpressionStatement( | |
| 3064 set_async_return_var, kNoSourcePosition), | |
| 3065 zone()); | |
| 3066 } | |
| 3018 | 3067 |
| 3019 TryStatement* try_catch_statement = | 3068 TryStatement* try_catch_statement = |
| 3020 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, | 3069 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, |
| 3021 catch_variable, catch_block, | 3070 catch_variable, catch_block, |
| 3022 kNoSourcePosition); | 3071 kNoSourcePosition); |
| 3023 | 3072 |
| 3024 // There is no TryCatchFinally node, so wrap it in an outer try/finally | 3073 // There is no TryCatchFinally node, so wrap it in an outer try/finally |
| 3025 Block* outer_try_block = | 3074 Block* outer_try_block = |
| 3026 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3075 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3027 outer_try_block->statements()->Add(try_catch_statement, zone()); | 3076 outer_try_block->statements()->Add(try_catch_statement, zone()); |
| 3028 | 3077 |
| 3029 // finally { %AsyncFunctionPromiseRelease(.promise) } | 3078 // finally { |
| 3079 // .is_rejection | |
| 3080 // ? %RejectPromise(.promise, .catch) | |
|
neis
2017/02/08 10:28:41
.catch should be .async_return_value
gsathya
2017/02/09 00:55:45
Done.
| |
| 3081 // : %ResolvePromise(.promise, .async_return_value); | |
| 3082 // %AsyncFunctionPromiseRelease(.promise); | |
| 3083 // return .promise; | |
| 3084 // } | |
| 3030 Block* finally_block = | 3085 Block* finally_block = |
| 3031 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3086 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3032 { | 3087 { |
| 3088 // .is_rejection | |
| 3089 // ? %RejectPromise(.promise, .catch) | |
| 3090 // : %ResolvePromise(.promise, .async_return_value); | |
| 3091 Expression* resolve_or_reject_promise = factory()->NewConditional( | |
| 3092 factory()->NewVariableProxy(is_rejection_var), BuildRejectPromise(), | |
| 3093 BuildResolvePromise(), kNoSourcePosition); | |
| 3094 finally_block->statements()->Add( | |
| 3095 factory()->NewExpressionStatement(resolve_or_reject_promise, | |
| 3096 kNoSourcePosition), | |
| 3097 zone()); | |
| 3098 | |
| 3099 // %AsyncFunctionPromiseRelease(.promise); | |
| 3033 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | 3100 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 3034 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3101 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
| 3035 Expression* call_promise_release = factory()->NewCallRuntime( | 3102 Expression* call_promise_release = factory()->NewCallRuntime( |
| 3036 Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); | 3103 Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); |
| 3037 Statement* promise_release = factory()->NewExpressionStatement( | 3104 Statement* promise_release = factory()->NewExpressionStatement( |
| 3038 call_promise_release, kNoSourcePosition); | 3105 call_promise_release, kNoSourcePosition); |
| 3039 finally_block->statements()->Add(promise_release, zone()); | 3106 finally_block->statements()->Add(promise_release, zone()); |
| 3107 | |
| 3108 // return .promise; | |
| 3109 Statement* return_promise = factory()->NewReturnStatement( | |
| 3110 factory()->NewVariableProxy(PromiseVariable()), kNoSourcePosition); | |
| 3111 | |
| 3112 // If we're in a try-catch-finally block of parameters block | |
| 3113 // desugaring, then we return the promise only on rejection. | |
| 3114 // The desugaring changes from | |
| 3115 // return .promise; | |
| 3116 // to | |
| 3117 // if (.is_rejection) { | |
| 3118 // return .promise; | |
| 3119 // } | |
|
neis
2017/02/08 10:28:41
Please also mention this in the main comment at th
gsathya
2017/02/09 00:55:44
Done.
| |
| 3120 if (is_parameter_block) { | |
| 3121 Expression* condition = factory()->NewCompareOperation( | |
| 3122 Token::EQ, factory()->NewVariableProxy(is_rejection_var), | |
| 3123 factory()->NewBooleanLiteral(true, kNoSourcePosition), | |
| 3124 kNoSourcePosition); | |
|
neis
2017/02/08 10:28:41
No need for a comparison here.
gsathya
2017/02/09 00:55:44
Why not? We need to return only in the case of rej
neis
2017/02/09 08:22:07
I meant you can just do "if (is_rejection_var) ...
| |
| 3125 return_promise = factory()->NewIfStatement( | |
| 3126 condition, return_promise, | |
| 3127 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); | |
| 3128 } | |
| 3129 finally_block->statements()->Add(return_promise, zone()); | |
| 3040 } | 3130 } |
| 3041 | 3131 |
| 3042 Statement* try_finally_statement = factory()->NewTryFinallyStatement( | 3132 Statement* try_finally_statement = factory()->NewTryFinallyStatement( |
| 3043 outer_try_block, finally_block, kNoSourcePosition); | 3133 outer_try_block, finally_block, kNoSourcePosition); |
| 3044 | 3134 |
| 3045 result->statements()->Add(try_finally_statement, zone()); | 3135 result->statements()->Add(try_finally_statement, zone()); |
| 3046 return result; | 3136 return result; |
| 3047 } | 3137 } |
| 3048 | 3138 |
| 3049 Assignment* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { | 3139 Assignment* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
| 3050 // .generator = %CreateJSGeneratorObject(...); | 3140 // .generator = %CreateJSGeneratorObject(...); |
| 3051 DCHECK_NOT_NULL(function_state_->generator_object_variable()); | 3141 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
| 3052 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 3142 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 3053 args->Add(factory()->NewThisFunction(pos), zone()); | 3143 args->Add(factory()->NewThisFunction(pos), zone()); |
| 3054 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos) | 3144 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos) |
| 3055 : ThisExpression(kNoSourcePosition), | 3145 : ThisExpression(kNoSourcePosition), |
| 3056 zone()); | 3146 zone()); |
| 3057 Expression* allocation = | 3147 Expression* allocation = |
| 3058 factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, pos); | 3148 factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, pos); |
| 3059 VariableProxy* proxy = | 3149 VariableProxy* proxy = |
| 3060 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 3150 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
| 3061 return factory()->NewAssignment(Token::INIT, proxy, allocation, | 3151 return factory()->NewAssignment(Token::INIT, proxy, allocation, |
| 3062 kNoSourcePosition); | 3152 kNoSourcePosition); |
| 3063 } | 3153 } |
| 3064 | 3154 |
| 3065 Expression* Parser::BuildResolvePromise(Expression* value, int pos) { | 3155 Expression* Parser::BuildResolvePromise() { |
| 3066 // %ResolvePromise(.promise, value), .promise | 3156 // %ResolvePromise(.promise, .async_return_variable), .promise |
| 3157 int pos = kNoSourcePosition; | |
|
adamk
2017/02/07 21:42:01
No need for this variable, just pass kNoSourcePosi
gsathya
2017/02/09 00:55:45
Done.
| |
| 3067 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 3158 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 3068 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3159 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
| 3069 args->Add(value, zone()); | 3160 args->Add(factory()->NewVariableProxy(AsyncReturnVariable()), zone()); |
| 3070 Expression* call_runtime = | 3161 Expression* call_runtime = |
| 3071 factory()->NewCallRuntime(Context::PROMISE_RESOLVE_INDEX, args, pos); | 3162 factory()->NewCallRuntime(Context::PROMISE_RESOLVE_INDEX, args, pos); |
| 3072 return factory()->NewBinaryOperation( | 3163 return call_runtime; |
| 3073 Token::COMMA, call_runtime, | |
| 3074 factory()->NewVariableProxy(PromiseVariable()), pos); | |
| 3075 } | 3164 } |
| 3076 | 3165 |
| 3077 Expression* Parser::BuildRejectPromise(Expression* value, int pos) { | 3166 Expression* Parser::BuildRejectPromise() { |
| 3078 // %promise_internal_reject(.promise, value, false), .promise | 3167 // %promise_internal_reject(.promise, .async_return_variable, false) |
| 3079 // Disables the additional debug event for the rejection since a debug event | 3168 // Disables the additional debug event for the rejection since a debug event |
| 3080 // already happened for the exception that got us here. | 3169 // already happened for the exception that got us here. |
| 3170 int pos = kNoSourcePosition; | |
|
adamk
2017/02/07 21:42:01
Same here as above.
gsathya
2017/02/09 00:55:45
Done.
| |
| 3081 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(3, zone()); | 3171 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(3, zone()); |
| 3082 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3172 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
| 3083 args->Add(value, zone()); | 3173 args->Add(factory()->NewVariableProxy(AsyncReturnVariable()), zone()); |
| 3084 args->Add(factory()->NewBooleanLiteral(false, pos), zone()); | 3174 args->Add(factory()->NewBooleanLiteral(false, pos), zone()); |
| 3085 Expression* call_runtime = factory()->NewCallRuntime( | 3175 Expression* call_runtime = factory()->NewCallRuntime( |
| 3086 Context::PROMISE_INTERNAL_REJECT_INDEX, args, pos); | 3176 Context::PROMISE_INTERNAL_REJECT_INDEX, args, pos); |
| 3087 return factory()->NewBinaryOperation( | 3177 return call_runtime; |
| 3088 Token::COMMA, call_runtime, | |
| 3089 factory()->NewVariableProxy(PromiseVariable()), pos); | |
| 3090 } | 3178 } |
| 3091 | 3179 |
| 3092 Variable* Parser::PromiseVariable() { | 3180 Variable* Parser::PromiseVariable() { |
| 3093 // Based on the various compilation paths, there are many different code | 3181 // Based on the various compilation paths, there are many different code |
| 3094 // paths which may be the first to access the Promise temporary. Whichever | 3182 // paths which may be the first to access the Promise temporary. Whichever |
| 3095 // comes first should create it and stash it in the FunctionState. | 3183 // comes first should create it and stash it in the FunctionState. |
| 3096 Variable* promise = function_state_->promise_variable(); | 3184 Variable* promise = function_state_->promise_variable(); |
| 3097 if (function_state_->promise_variable() == nullptr) { | 3185 if (function_state_->promise_variable() == nullptr) { |
| 3098 promise = scope()->NewTemporary(ast_value_factory()->empty_string()); | 3186 promise = scope()->NewTemporary(ast_value_factory()->empty_string()); |
| 3099 function_state_->set_promise_variable(promise); | 3187 function_state_->set_promise_variable(promise); |
| 3100 } | 3188 } |
| 3101 return promise; | 3189 return promise; |
| 3102 } | 3190 } |
| 3103 | 3191 |
| 3192 Variable* Parser::AsyncReturnVariable() { | |
| 3193 // Based on the various compilation paths, there are many different code | |
| 3194 // paths which may be the first to access the Promise temporary. Whichever | |
|
neis
2017/02/08 10:28:41
s/Promise/something else/
gsathya
2017/02/09 00:55:44
Done.
| |
| 3195 // comes first should create it and stash it in the FunctionState. | |
| 3196 Variable* async_return = function_state_->async_return_variable(); | |
| 3197 if (async_return == nullptr) { | |
| 3198 async_return = scope()->NewTemporary(ast_value_factory()->empty_string()); | |
| 3199 function_state_->set_async_return_variable(async_return); | |
| 3200 } | |
| 3201 return async_return; | |
| 3202 } | |
| 3203 | |
| 3104 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { | 3204 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { |
| 3105 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); | 3205 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); |
| 3106 VariableProxy* generator = | 3206 VariableProxy* generator = |
| 3107 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 3207 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
| 3108 // The position of the yield is important for reporting the exception | 3208 // The position of the yield is important for reporting the exception |
| 3109 // caused by calling the .throw method on a generator suspended at the | 3209 // caused by calling the .throw method on a generator suspended at the |
| 3110 // initial yield (i.e. right after generator instantiation). | 3210 // initial yield (i.e. right after generator instantiation). |
| 3111 return factory()->NewYield(generator, assignment, scope()->start_position(), | 3211 return factory()->NewYield(generator, assignment, scope()->start_position(), |
| 3112 Yield::kOnExceptionThrow); | 3212 Yield::kOnExceptionThrow); |
| 3113 } | 3213 } |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3775 zone()); | 3875 zone()); |
| 3776 } | 3876 } |
| 3777 | 3877 |
| 3778 // This method completes the desugaring of the body of async_function. | 3878 // This method completes the desugaring of the body of async_function. |
| 3779 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, Block* block, | 3879 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, Block* block, |
| 3780 Expression* return_value, bool* ok) { | 3880 Expression* return_value, bool* ok) { |
| 3781 // function async_function() { | 3881 // function async_function() { |
| 3782 // .generator_object = %CreateJSGeneratorObject(); | 3882 // .generator_object = %CreateJSGeneratorObject(); |
| 3783 // BuildRejectPromiseOnException({ | 3883 // BuildRejectPromiseOnException({ |
| 3784 // ... block ... | 3884 // ... block ... |
| 3785 // return %ResolvePromise(.promise, expr), .promise; | 3885 // .async_return_var = expr; |
| 3786 // }) | 3886 // }) |
| 3787 // } | 3887 // } |
| 3788 | 3888 |
| 3789 return_value = BuildResolvePromise(return_value, return_value->position()); | 3889 Assignment* set_async_return_var = factory()->NewAssignment( |
| 3790 block->statements()->Add( | 3890 Token::INIT, factory()->NewVariableProxy(AsyncReturnVariable()), |
| 3791 factory()->NewReturnStatement(return_value, return_value->position()), | 3891 return_value, kNoSourcePosition); |
|
neis
2017/02/08 10:28:41
This must be ASSIGN, not INIT.
gsathya
2017/02/09 00:55:45
Done.
| |
| 3792 zone()); | 3892 block->statements()->Add(factory()->NewExpressionStatement( |
| 3893 set_async_return_var, kNoSourcePosition), | |
| 3894 zone()); | |
| 3793 block = BuildRejectPromiseOnException(block); | 3895 block = BuildRejectPromiseOnException(block); |
| 3794 body->Add(block, zone()); | 3896 body->Add(block, zone()); |
| 3795 } | 3897 } |
| 3796 | 3898 |
| 3797 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { | 3899 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { |
| 3798 // yield do { | 3900 // yield do { |
| 3799 // tmp = <operand>; | 3901 // tmp = <operand>; |
| 3800 // %AsyncFunctionAwait(.generator_object, tmp, .promise); | 3902 // %AsyncFunctionAwait(.generator_object, tmp, .promise); |
| 3801 // .promise | 3903 // .promise |
| 3802 // } | 3904 // } |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5026 | 5128 |
| 5027 return final_loop; | 5129 return final_loop; |
| 5028 } | 5130 } |
| 5029 | 5131 |
| 5030 #undef CHECK_OK | 5132 #undef CHECK_OK |
| 5031 #undef CHECK_OK_VOID | 5133 #undef CHECK_OK_VOID |
| 5032 #undef CHECK_FAILED | 5134 #undef CHECK_FAILED |
| 5033 | 5135 |
| 5034 } // namespace internal | 5136 } // namespace internal |
| 5035 } // namespace v8 | 5137 } // namespace v8 |
| OLD | NEW |