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

Side by Side Diff: corelib/src/implementation/future_implementation.dart

Issue 8400038: Use strict equality when comparing with null, especially when null is a default value. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « corelib/src/expect.dart ('k') | corelib/src/implementation/promise_implementation.dart » ('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 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // Dart core library. 2 // Dart core library.
3 3
4 /** 4 /**
5 * Thrown if client tries to obtain value or exception 5 * Thrown if client tries to obtain value or exception
6 * before a future has completed. 6 * before a future has completed.
7 */ 7 */
8 class FutureNotCompleteException implements Exception { 8 class FutureNotCompleteException implements Exception {
9 FutureNotCompleteException() {} 9 FutureNotCompleteException() {}
10 } 10 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 throw new FutureNotCompleteException(); 68 throw new FutureNotCompleteException();
69 } 69 }
70 return _exception; 70 return _exception;
71 } 71 }
72 72
73 bool get isComplete() { 73 bool get isComplete() {
74 return _isComplete; 74 return _isComplete;
75 } 75 }
76 76
77 bool get hasValue() { 77 bool get hasValue() {
78 return isComplete && exception == null; 78 return isComplete && _exception === null;
79 } 79 }
80 80
81 void then(void onComplete(T value)) { 81 void then(void onComplete(T value)) {
82 if (hasValue) { 82 if (hasValue) {
83 onComplete(value); 83 onComplete(value);
84 } else { 84 } else {
85 _listeners.add(onComplete); 85 _listeners.add(onComplete);
86 } 86 }
87 } 87 }
88 88
(...skipping 23 matching lines...) Expand all
112 112
113 void _setValue(T value) { 113 void _setValue(T value) {
114 if (_isComplete) { 114 if (_isComplete) {
115 throw new FutureAlreadyCompleteException(); 115 throw new FutureAlreadyCompleteException();
116 } 116 }
117 _value = value; 117 _value = value;
118 _complete(); 118 _complete();
119 } 119 }
120 120
121 void _setException(var exception) { 121 void _setException(var exception) {
122 if (exception == null) { 122 if (exception === null) {
123 // null is not a legal value for the exception of a Future 123 // null is not a legal value for the exception of a Future
124 throw new IllegalArgumentException(null); 124 throw new IllegalArgumentException(null);
125 } 125 }
126 if (_isComplete) { 126 if (_isComplete) {
127 throw new FutureAlreadyCompleteException(); 127 throw new FutureAlreadyCompleteException();
128 } 128 }
129 _exception = exception; 129 _exception = exception;
130 _complete(); 130 _complete();
131 } 131 }
132 } 132 }
133 133
134 class CompleterImpl<T> implements Completer<T> { 134 class CompleterImpl<T> implements Completer<T> {
135 135
136 final FutureImpl<T> _futureImpl; 136 final FutureImpl<T> _futureImpl;
137 137
138 CompleterImpl() : _futureImpl = new FutureImpl() {} 138 CompleterImpl() : _futureImpl = new FutureImpl() {}
139 139
140 Future<T> get future() { 140 Future<T> get future() {
141 return _futureImpl; 141 return _futureImpl;
142 } 142 }
143 143
144 void complete(T value) { 144 void complete(T value) {
145 _futureImpl._setValue(value); 145 _futureImpl._setValue(value);
146 } 146 }
147 147
148 void completeException(var exception) { 148 void completeException(var exception) {
149 _futureImpl._setException(exception); 149 _futureImpl._setException(exception);
150 } 150 }
151 } 151 }
OLDNEW
« no previous file with comments | « corelib/src/expect.dart ('k') | corelib/src/implementation/promise_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698