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

Side by Side Diff: src/parsing/rewriter.cc

Issue 2537413003: [parsing] Fix bug in completion value of try-finally. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | test/mjsunit/es6/completion.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/rewriter.h" 5 #include "src/parsing/rewriter.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 #include "src/parsing/parse-info.h" 9 #include "src/parsing/parse-info.h"
10 #include "src/parsing/parser.h" 10 #include "src/parsing/parser.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 replacement_ = is_set_ && set_in_try ? node : AssignUndefinedBefore(node); 237 replacement_ = is_set_ && set_in_try ? node : AssignUndefinedBefore(node);
238 is_set_ = true; 238 is_set_ = true;
239 } 239 }
240 240
241 241
242 void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) { 242 void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) {
243 // Only rewrite finally if it could contain 'break' or 'continue'. Always 243 // Only rewrite finally if it could contain 'break' or 'continue'. Always
244 // rewrite try. 244 // rewrite try.
245 if (breakable_) { 245 if (breakable_) {
246 bool set_after = is_set_; 246 bool set_after = is_set_;
adamk 2016/11/30 18:13:19 Don't need this anymore
neis 2016/12/01 10:22:44 Acknowledged.
247 // Only set result before a 'break' or 'continue'. 247 // Only set result before a 'break' or 'continue'.
adamk 2016/11/30 18:13:19 This comment sounds redundant with the longer comm
neis 2016/12/01 10:22:44 Not sure what you mean. The comment here justifie
adamk 2016/12/01 18:49:31 On re-reading them together, I think I agree that
248 is_set_ = true; 248 is_set_ = true;
249 Visit(node->finally_block()); 249 Visit(node->finally_block());
250 node->set_finally_block(replacement_->AsBlock()); 250 node->set_finally_block(replacement_->AsBlock());
251 // Save .result value at the beginning of the finally block and restore it 251 // Save .result value at the beginning of the finally block and restore it
252 // at the end again: ".backup = .result; ...; .result = .backup" 252 // at the end again: ".backup = .result; ...; .result = .backup"
253 // This is necessary because the finally block does not normally contribute 253 // This is necessary because the finally block does not normally contribute
254 // to the completion value. 254 // to the completion value.
255 CHECK_NOT_NULL(closure_scope()); 255 CHECK_NOT_NULL(closure_scope());
256 Variable* backup = closure_scope()->NewTemporary( 256 Variable* backup = closure_scope()->NewTemporary(
257 factory()->ast_value_factory()->dot_result_string()); 257 factory()->ast_value_factory()->dot_result_string());
258 Expression* backup_proxy = factory()->NewVariableProxy(backup); 258 Expression* backup_proxy = factory()->NewVariableProxy(backup);
259 Expression* result_proxy = factory()->NewVariableProxy(result_); 259 Expression* result_proxy = factory()->NewVariableProxy(result_);
260 Expression* save = factory()->NewAssignment( 260 Expression* save = factory()->NewAssignment(
261 Token::ASSIGN, backup_proxy, result_proxy, kNoSourcePosition); 261 Token::ASSIGN, backup_proxy, result_proxy, kNoSourcePosition);
262 Expression* restore = factory()->NewAssignment( 262 Expression* restore = factory()->NewAssignment(
263 Token::ASSIGN, result_proxy, backup_proxy, kNoSourcePosition); 263 Token::ASSIGN, result_proxy, backup_proxy, kNoSourcePosition);
264 node->finally_block()->statements()->InsertAt( 264 node->finally_block()->statements()->InsertAt(
265 0, factory()->NewExpressionStatement(save, kNoSourcePosition), zone()); 265 0, factory()->NewExpressionStatement(save, kNoSourcePosition), zone());
266 node->finally_block()->statements()->Add( 266 node->finally_block()->statements()->Add(
267 factory()->NewExpressionStatement(restore, kNoSourcePosition), zone()); 267 factory()->NewExpressionStatement(restore, kNoSourcePosition), zone());
268 is_set_ = set_after;
269 } 268 }
270 Visit(node->try_block()); 269 Visit(node->try_block());
271 node->set_try_block(replacement_->AsBlock()); 270 node->set_try_block(replacement_->AsBlock());
272 271
273 replacement_ = is_set_ ? node : AssignUndefinedBefore(node); 272 replacement_ = is_set_ ? node : AssignUndefinedBefore(node);
274 is_set_ = true; 273 is_set_ = true;
275 } 274 }
276 275
277 276
278 void Processor::VisitSwitchStatement(SwitchStatement* node) { 277 void Processor::VisitSwitchStatement(SwitchStatement* node) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 processor.SetResult(undef), expr->position()); 411 processor.SetResult(undef), expr->position());
413 body->Add(completion, factory->zone()); 412 body->Add(completion, factory->zone());
414 } 413 }
415 } 414 }
416 return true; 415 return true;
417 } 416 }
418 417
419 418
420 } // namespace internal 419 } // namespace internal
421 } // namespace v8 420 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/completion.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698