Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: runtime/vm/ast_transformer.cc

Issue 2692803006: Track the 'awaiter return' call stack use it to detect uncaught exceptions in async functions (Closed)
Patch Set: rmacnak review Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/ast_transformer.h" 5 #include "vm/ast_transformer.h"
6 6
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/parser.h" 8 #include "vm/parser.h"
9 #include "vm/thread.h" 9 #include "vm/thread.h"
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 } 130 }
131 131
132 132
133 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { 133 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) {
134 // Await transformation: 134 // Await transformation:
135 // 135 //
136 // :await_temp_var_X = <expr>; 136 // :await_temp_var_X = <expr>;
137 // AwaitMarker(kNewContinuationState); 137 // AwaitMarker(kNewContinuationState);
138 // :result_param = _awaitHelper( 138 // :result_param = _awaitHelper(
139 // :await_temp_var_X, :async_then_callback, :async_catch_error_callback); 139 // :await_temp_var_X,
140 // :async_then_callback,
141 // :async_catch_error_callback,
142 // :async_op);
140 // return; // (return_type() == kContinuationTarget) 143 // return; // (return_type() == kContinuationTarget)
141 // 144 //
142 // :saved_try_ctx_var = :await_saved_try_ctx_var_y; 145 // :saved_try_ctx_var = :await_saved_try_ctx_var_y;
143 // :await_temp_var_(X+1) = :result_param; 146 // :await_temp_var_(X+1) = :result_param;
144 147
145 const TokenPosition token_pos = ST(node->token_pos()); 148 const TokenPosition token_pos = ST(node->token_pos());
146 LocalVariable* async_op = 149 LocalVariable* async_op =
147 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperation()); 150 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperation());
148 LocalVariable* async_then_callback = 151 LocalVariable* async_then_callback =
149 GetVariableInScope(preamble_->scope(), Symbols::AsyncThenCallback()); 152 GetVariableInScope(preamble_->scope(), Symbols::AsyncThenCallback());
150 LocalVariable* async_catch_error_callback = GetVariableInScope( 153 LocalVariable* async_catch_error_callback = GetVariableInScope(
151 preamble_->scope(), Symbols::AsyncCatchErrorCallback()); 154 preamble_->scope(), Symbols::AsyncCatchErrorCallback());
152 LocalVariable* result_param = 155 LocalVariable* result_param =
153 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperationParam()); 156 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperationParam());
154 LocalVariable* error_param = GetVariableInScope( 157 LocalVariable* error_param = GetVariableInScope(
155 preamble_->scope(), Symbols::AsyncOperationErrorParam()); 158 preamble_->scope(), Symbols::AsyncOperationErrorParam());
156 LocalVariable* stack_trace_param = GetVariableInScope( 159 LocalVariable* stack_trace_param = GetVariableInScope(
157 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); 160 preamble_->scope(), Symbols::AsyncOperationStackTraceParam());
158 161
159 AstNode* transformed_expr = Transform(node->expr()); 162 AstNode* transformed_expr = Transform(node->expr());
160 LocalVariable* await_temp = 163 LocalVariable* await_temp =
161 AddNewTempVarToPreamble(transformed_expr, ST(node->token_pos())); 164 AddNewTempVarToPreamble(transformed_expr, ST(node->token_pos()));
162 165
163 AwaitMarkerNode* await_marker = 166 AwaitMarkerNode* await_marker =
164 new (Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos); 167 new (Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos);
165 preamble_->Add(await_marker); 168 preamble_->Add(await_marker);
166 169
167 // :result_param = _awaitHelper( 170 // :result_param = _awaitHelper(
168 // :await_temp, :async_then_callback, :async_catch_error_callback) 171 // :await_temp,
172 // :async_then_callback,
173 // :async_catch_error_callback,
174 // :async_op)
169 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); 175 const Library& async_lib = Library::Handle(Library::AsyncLibrary());
170 const Function& async_await_helper = Function::ZoneHandle( 176 const Function& async_await_helper = Function::ZoneHandle(
171 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper())); 177 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper()));
172 ASSERT(!async_await_helper.IsNull()); 178 ASSERT(!async_await_helper.IsNull());
173 ArgumentListNode* async_await_helper_args = 179 ArgumentListNode* async_await_helper_args =
174 new (Z) ArgumentListNode(token_pos); 180 new (Z) ArgumentListNode(token_pos);
175 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, await_temp)); 181 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, await_temp));
176 async_await_helper_args->Add( 182 async_await_helper_args->Add(
177 new (Z) LoadLocalNode(token_pos, async_then_callback)); 183 new (Z) LoadLocalNode(token_pos, async_then_callback));
178 async_await_helper_args->Add( 184 async_await_helper_args->Add(
179 new (Z) LoadLocalNode(token_pos, async_catch_error_callback)); 185 new (Z) LoadLocalNode(token_pos, async_catch_error_callback));
186 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, async_op));
180 StaticCallNode* await_helper_call = new (Z) StaticCallNode( 187 StaticCallNode* await_helper_call = new (Z) StaticCallNode(
181 node->token_pos(), async_await_helper, async_await_helper_args); 188 node->token_pos(), async_await_helper, async_await_helper_args);
182 189
183 preamble_->Add( 190 preamble_->Add(
184 new (Z) StoreLocalNode(token_pos, result_param, await_helper_call)); 191 new (Z) StoreLocalNode(token_pos, result_param, await_helper_call));
185 192
186 ReturnNode* continuation_return = new (Z) ReturnNode(token_pos); 193 ReturnNode* continuation_return = new (Z) ReturnNode(token_pos);
187 continuation_return->set_return_type(ReturnNode::kContinuationTarget); 194 continuation_return->set_return_type(ReturnNode::kContinuationTarget);
188 preamble_->Add(continuation_return); 195 preamble_->Add(continuation_return);
189 196
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 521 }
515 522
516 523
517 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { 524 void AwaitTransformer::VisitThrowNode(ThrowNode* node) {
518 AstNode* new_exception = Transform(node->exception()); 525 AstNode* new_exception = Transform(node->exception());
519 result_ = MakeName( 526 result_ = MakeName(
520 new (Z) ThrowNode(node->token_pos(), new_exception, node->stacktrace())); 527 new (Z) ThrowNode(node->token_pos(), new_exception, node->stacktrace()));
521 } 528 }
522 529
523 } // namespace dart 530 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698