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 3112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3123 if (param_scope != nullptr) { | 3123 if (param_scope != nullptr) { |
3124 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 3124 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
3125 } | 3125 } |
3126 init_block->statements()->Add(param_block, zone()); | 3126 init_block->statements()->Add(param_block, zone()); |
3127 } | 3127 } |
3128 } | 3128 } |
3129 return init_block; | 3129 return init_block; |
3130 } | 3130 } |
3131 | 3131 |
3132 Block* Parser::BuildRejectPromiseOnException(Block* inner_block, bool* ok) { | 3132 Block* Parser::BuildRejectPromiseOnException(Block* inner_block, bool* ok) { |
3133 // .promise = %CreatePromise(); | 3133 // .promise = %AsyncFunctionPromiseCreate(); |
3134 // .debug_is_active = %_DebugIsActive(); | |
3135 // if (.debug_is_active) %DebugPushPromise(.promise); | |
3136 // try { | 3134 // try { |
3137 // <inner_block> | 3135 // <inner_block> |
3138 // } catch (.catch) { | 3136 // } catch (.catch) { |
3139 // %RejectPromise(.promise, .catch); | 3137 // %RejectPromise(.promise, .catch); |
3140 // return .promise; | 3138 // return .promise; |
3141 // } finally { | 3139 // } finally { |
3142 // if (.debug_is_active) %DebugPopPromise(); | 3140 // %AsyncFunctionPromiseRelease(.promise); |
3143 // } | 3141 // } |
3144 Block* result = factory()->NewBlock(nullptr, 4, true, kNoSourcePosition); | 3142 Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); |
3145 | 3143 |
3146 // .promise = %CreatePromise(); | 3144 // .promise = %AsyncFunctionPromiseCreate(); |
3147 Statement* set_promise; | 3145 Statement* set_promise; |
3148 { | 3146 { |
3149 Expression* create_promise = factory()->NewCallRuntime( | 3147 Expression* create_promise = factory()->NewCallRuntime( |
3150 Context::PROMISE_CREATE_INDEX, | 3148 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, |
3151 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); | 3149 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); |
3152 Assignment* assign_promise = factory()->NewAssignment( | 3150 Assignment* assign_promise = factory()->NewAssignment( |
3153 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), | 3151 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), |
3154 create_promise, kNoSourcePosition); | 3152 create_promise, kNoSourcePosition); |
3155 set_promise = | 3153 set_promise = |
3156 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); | 3154 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); |
3157 } | 3155 } |
3158 result->statements()->Add(set_promise, zone()); | 3156 result->statements()->Add(set_promise, zone()); |
3159 | 3157 |
3160 Variable* debug_is_active = | |
3161 scope()->NewTemporary(ast_value_factory()->empty_string()); | |
3162 // .debug_is_active = %_DebugIsActive(); | |
3163 Statement* set_debug_is_active; | |
3164 { | |
3165 Expression* call_debug_is_active = factory()->NewCallRuntime( | |
3166 Runtime::kInlineDebugIsActive, | |
3167 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); | |
3168 Assignment* assign_debug_is_active = factory()->NewAssignment( | |
3169 Token::INIT, factory()->NewVariableProxy(debug_is_active), | |
3170 call_debug_is_active, kNoSourcePosition); | |
3171 set_debug_is_active = factory()->NewExpressionStatement( | |
3172 assign_debug_is_active, kNoSourcePosition); | |
3173 } | |
3174 result->statements()->Add(set_debug_is_active, zone()); | |
3175 | |
3176 // if (.debug_is_active) %DebugPushPromise(.promise); | |
3177 Statement* conditionally_debug_push_promise; | |
3178 { | |
3179 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | |
3180 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | |
3181 Expression* call_push_promise = factory()->NewCallRuntime( | |
3182 Runtime::kDebugPushPromise, args, kNoSourcePosition); | |
3183 Statement* debug_push_promise = | |
3184 factory()->NewExpressionStatement(call_push_promise, kNoSourcePosition); | |
3185 conditionally_debug_push_promise = factory()->NewIfStatement( | |
3186 factory()->NewVariableProxy(debug_is_active), debug_push_promise, | |
3187 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); | |
3188 } | |
3189 result->statements()->Add(conditionally_debug_push_promise, zone()); | |
3190 | |
3191 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } | 3158 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } |
3192 Scope* catch_scope = NewScope(CATCH_SCOPE); | 3159 Scope* catch_scope = NewScope(CATCH_SCOPE); |
3193 catch_scope->set_is_hidden(); | 3160 catch_scope->set_is_hidden(); |
3194 Variable* catch_variable = | 3161 Variable* catch_variable = |
3195 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 3162 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, |
3196 kCreatedInitialized, NORMAL_VARIABLE); | 3163 kCreatedInitialized, NORMAL_VARIABLE); |
3197 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3164 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3198 | 3165 |
3199 Expression* promise_reject = BuildRejectPromise( | 3166 Expression* promise_reject = BuildRejectPromise( |
3200 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); | 3167 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
3201 ReturnStatement* return_promise_reject = | 3168 ReturnStatement* return_promise_reject = |
3202 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); | 3169 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); |
3203 catch_block->statements()->Add(return_promise_reject, zone()); | 3170 catch_block->statements()->Add(return_promise_reject, zone()); |
3204 | 3171 |
3205 TryStatement* try_catch_statement = | 3172 TryStatement* try_catch_statement = |
3206 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, | 3173 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, |
3207 catch_variable, catch_block, | 3174 catch_variable, catch_block, |
3208 kNoSourcePosition); | 3175 kNoSourcePosition); |
3209 | 3176 |
3210 // There is no TryCatchFinally node, so wrap it in an outer try/finally | 3177 // There is no TryCatchFinally node, so wrap it in an outer try/finally |
3211 Block* outer_try_block = | 3178 Block* outer_try_block = |
3212 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3179 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3213 outer_try_block->statements()->Add(try_catch_statement, zone()); | 3180 outer_try_block->statements()->Add(try_catch_statement, zone()); |
3214 | 3181 |
3215 // finally { if (.debug_is_active) %DebugPopPromise(); } | 3182 // finally { %AsyncFunctionPromiseRelease(.promise) } |
3216 Block* finally_block = | 3183 Block* finally_block = |
3217 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3184 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3218 { | 3185 { |
3219 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(0, zone()); | 3186 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
3220 Expression* call_pop_promise = factory()->NewCallRuntime( | 3187 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
3221 Runtime::kDebugPopPromise, args, kNoSourcePosition); | 3188 Expression* call_promise_release = factory()->NewCallRuntime( |
3222 Statement* debug_pop_promise = | 3189 Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); |
3223 factory()->NewExpressionStatement(call_pop_promise, kNoSourcePosition); | 3190 Statement* promise_release = factory()->NewExpressionStatement( |
3224 Statement* conditionally_debug_pop_promise = factory()->NewIfStatement( | 3191 call_promise_release, kNoSourcePosition); |
3225 factory()->NewVariableProxy(debug_is_active), debug_pop_promise, | 3192 finally_block->statements()->Add(promise_release, zone()); |
3226 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); | |
3227 finally_block->statements()->Add(conditionally_debug_pop_promise, zone()); | |
3228 } | 3193 } |
3229 | 3194 |
3230 Statement* try_finally_statement = factory()->NewTryFinallyStatement( | 3195 Statement* try_finally_statement = factory()->NewTryFinallyStatement( |
3231 outer_try_block, finally_block, kNoSourcePosition); | 3196 outer_try_block, finally_block, kNoSourcePosition); |
3232 | 3197 |
3233 result->statements()->Add(try_finally_statement, zone()); | 3198 result->statements()->Add(try_finally_statement, zone()); |
3234 return result; | 3199 return result; |
3235 } | 3200 } |
3236 | 3201 |
3237 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { | 3202 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5605 | 5570 |
5606 return final_loop; | 5571 return final_loop; |
5607 } | 5572 } |
5608 | 5573 |
5609 #undef CHECK_OK | 5574 #undef CHECK_OK |
5610 #undef CHECK_OK_VOID | 5575 #undef CHECK_OK_VOID |
5611 #undef CHECK_FAILED | 5576 #undef CHECK_FAILED |
5612 | 5577 |
5613 } // namespace internal | 5578 } // namespace internal |
5614 } // namespace v8 | 5579 } // namespace v8 |
OLD | NEW |