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

Side by Side Diff: runtime/lib/core_patch.dart

Issue 1682173008: ‘Yield* e' should not access e.current eagerly (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import "dart:math"; 5 import "dart:math";
6 import "dart:typed_data"; 6 import "dart:typed_data";
7 7
8 // Equivalent of calling FATAL from C++ code. 8 // Equivalent of calling FATAL from C++ code.
9 _fatal(msg) native "DartCore_fatal"; 9 _fatal(msg) native "DartCore_fatal";
10 10
(...skipping 22 matching lines...) Expand all
33 const _SyncIterable(this.moveNextFn); 33 const _SyncIterable(this.moveNextFn);
34 34
35 get iterator { 35 get iterator {
36 return new _SyncIterator(moveNextFn._clone()); 36 return new _SyncIterator(moveNextFn._clone());
37 } 37 }
38 } 38 }
39 39
40 class _SyncIterator implements Iterator { 40 class _SyncIterator implements Iterator {
41 bool isYieldEach; // Set by generated code for the yield* statement. 41 bool isYieldEach; // Set by generated code for the yield* statement.
42 Iterator yieldEachIterator; 42 Iterator yieldEachIterator;
43 var current; // Set by generated code for the yield and yield* statement. 43 var _current; // Set by generated code for the yield and yield* statement.
44 SyncGeneratorCallback moveNextFn; 44 SyncGeneratorCallback moveNextFn;
45 45
46 get current => yieldEachIterator != null
47 ? yieldEachIterator.current
48 : _current;
49
46 _SyncIterator(this.moveNextFn); 50 _SyncIterator(this.moveNextFn);
47 51
48 bool moveNext() { 52 bool moveNext() {
49 if (moveNextFn == null) { 53 if (moveNextFn == null) {
50 return false; 54 return false;
51 } 55 }
52 while(true) { 56 while(true) {
53 if (yieldEachIterator != null) { 57 if (yieldEachIterator != null) {
54 if (yieldEachIterator.moveNext()) { 58 if (yieldEachIterator.moveNext()) {
55 current = yieldEachIterator.current;
56 return true; 59 return true;
57 } 60 }
58 yieldEachIterator = null; 61 yieldEachIterator = null;
59 } 62 }
60 isYieldEach = false; 63 isYieldEach = false;
61 if (!moveNextFn(this)) { 64 if (!moveNextFn(this)) {
62 moveNextFn = null; 65 moveNextFn = null;
63 current = null; 66 _current = null;
64 return false; 67 return false;
65 } 68 }
66 if (isYieldEach) { 69 if (isYieldEach) {
Ivan Posva 2016/02/13 07:03:03 Can you please explain in a comment how this code
hausner 2016/02/13 07:13:06 Yes, the generator sets this value when it reaches
Ivan Posva 2016/02/13 07:27:09 I understood the above comment as the field being
67 // Spec mandates: it is a dynamic error if the class of [the object 70 // Spec mandates: it is a dynamic error if the class of [the object
68 // returned by yield*] does not implement Iterable. 71 // returned by yield*] does not implement Iterable.
69 yieldEachIterator = (current as Iterable).iterator; 72 yieldEachIterator = (_current as Iterable).iterator;
73 _current = null;
70 continue; 74 continue;
71 } 75 }
72 return true; 76 return true;
73 } 77 }
74 } 78 }
75 } 79 }
76 80
77 patch class StackTrace { 81 patch class StackTrace {
78 /* patch */ static StackTrace get current native "StackTrace_current"; 82 /* patch */ static StackTrace get current native "StackTrace_current";
79 } 83 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698