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