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/ast/ast-numbering.h" | 5 #include "src/ast/ast-numbering.h" |
6 | 6 |
7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 IncrementNodeCount(); | 242 IncrementNodeCount(); |
243 VisitVariableProxy(node->proxy()); | 243 VisitVariableProxy(node->proxy()); |
244 VisitFunctionLiteral(node->fun()); | 244 VisitFunctionLiteral(node->fun()); |
245 } | 245 } |
246 | 246 |
247 | 247 |
248 void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) { | 248 void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) { |
249 IncrementNodeCount(); | 249 IncrementNodeCount(); |
250 node->set_base_id(ReserveIdRange(CallRuntime::num_ids())); | 250 node->set_base_id(ReserveIdRange(CallRuntime::num_ids())); |
251 VisitArguments(node->arguments()); | 251 VisitArguments(node->arguments()); |
| 252 // To support catch prediction within async/await: |
| 253 // |
| 254 // The AstNumberingVisitor is when catch prediction currently occurs, and it |
| 255 // is the only common point that has access to this information. The parser |
| 256 // just doesn't know yet. Take the following two cases of catch prediction: |
| 257 // |
| 258 // try { await fn(); } catch (e) { } |
| 259 // try { await fn(); } finally { } |
| 260 // |
| 261 // When parsing the await that we want to mark as caught or uncaught, it's |
| 262 // not yet known whether it will be followed by a 'finally' or a 'catch. |
| 263 // The AstNumberingVisitor is what learns whether it is caught. To make |
| 264 // the information available later to the runtime, the AstNumberingVisitor |
| 265 // has to stash it somewhere. Changing the runtime function into another |
| 266 // one in ast-numbering seemed like a simple and straightforward solution to |
| 267 // that problem. |
| 268 if (node->is_jsruntime() && |
| 269 node->context_index() == Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX && |
| 270 catch_prediction_ == HandlerTable::ASYNC_AWAIT) { |
| 271 node->set_context_index(Context::ASYNC_FUNCTION_AWAIT_UNCAUGHT_INDEX); |
| 272 } |
252 } | 273 } |
253 | 274 |
254 | 275 |
255 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { | 276 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { |
256 IncrementNodeCount(); | 277 IncrementNodeCount(); |
257 DisableCrankshaft(kWithStatement); | 278 DisableCrankshaft(kWithStatement); |
258 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); | 279 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); |
259 Visit(node->expression()); | 280 Visit(node->expression()); |
260 Visit(node->statement()); | 281 Visit(node->statement()); |
261 } | 282 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 } | 608 } |
588 | 609 |
589 | 610 |
590 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, | 611 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, |
591 FunctionLiteral* function) { | 612 FunctionLiteral* function) { |
592 AstNumberingVisitor visitor(isolate, zone); | 613 AstNumberingVisitor visitor(isolate, zone); |
593 return visitor.Renumber(function); | 614 return visitor.Renumber(function); |
594 } | 615 } |
595 } // namespace internal | 616 } // namespace internal |
596 } // namespace v8 | 617 } // namespace v8 |
OLD | NEW |