OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Patch file for dart:core classes. | 5 // Patch file for dart:core classes. |
6 import "dart:_internal" as _symbol_dev; | 6 import "dart:_internal" as _symbol_dev; |
7 import 'dart:_interceptors'; | 7 import 'dart:_interceptors'; |
8 import 'dart:_js_helper' show patch, | 8 import 'dart:_js_helper' show patch, |
9 checkInt, | 9 checkInt, |
10 getRuntimeType, | 10 getRuntimeType, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 144 } |
145 | 145 |
146 @patch | 146 @patch |
147 StackTrace get stackTrace => Primitives.extractStackTrace(this); | 147 StackTrace get stackTrace => Primitives.extractStackTrace(this); |
148 } | 148 } |
149 | 149 |
150 // Patch for DateTime implementation. | 150 // Patch for DateTime implementation. |
151 @patch | 151 @patch |
152 class DateTime { | 152 class DateTime { |
153 @patch | 153 @patch |
| 154 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
| 155 {bool isUtc: false}) |
| 156 : this._withValue(millisecondsSinceEpoch, isUtc: isUtc); |
| 157 |
| 158 @patch |
| 159 DateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, |
| 160 {bool isUtc: false}) |
| 161 : this._withValue( |
| 162 _microsecondInRoundedMilliseconds(microsecondsSinceEpoch), |
| 163 isUtc: isUtc); |
| 164 |
| 165 @patch |
154 DateTime._internal(int year, | 166 DateTime._internal(int year, |
155 int month, | 167 int month, |
156 int day, | 168 int day, |
157 int hour, | 169 int hour, |
158 int minute, | 170 int minute, |
159 int second, | 171 int second, |
160 int millisecond, | 172 int millisecond, |
| 173 int microsecond, |
161 bool isUtc) | 174 bool isUtc) |
162 // checkBool is manually inlined here because dart2js doesn't inline it | 175 // checkBool is manually inlined here because dart2js doesn't inline it |
163 // and [isUtc] is usually a constant. | 176 // and [isUtc] is usually a constant. |
164 : this.isUtc = isUtc is bool ? isUtc : throw new ArgumentError(isUtc), | 177 : this.isUtc = isUtc is bool |
165 millisecondsSinceEpoch = checkInt(Primitives.valueFromDecomposedDate( | 178 ? isUtc |
166 year, month, day, hour, minute, second, millisecond, isUtc)); | 179 : throw new ArgumentError.value(isUtc, 'isUtc'), |
| 180 _value = checkInt(Primitives.valueFromDecomposedDate( |
| 181 year, month, day, hour, minute, second, |
| 182 millisecond + _microsecondInRoundedMilliseconds(microsecond), |
| 183 isUtc)); |
167 | 184 |
168 @patch | 185 @patch |
169 DateTime._now() | 186 DateTime._now() |
170 : isUtc = false, | 187 : isUtc = false, |
171 millisecondsSinceEpoch = Primitives.dateNow(); | 188 _value = Primitives.dateNow(); |
172 | 189 |
173 @patch | 190 /// Rounds the given [microsecond] to the nearest milliseconds value. |
174 static int _brokenDownDateToMillisecondsSinceEpoch( | 191 /// |
175 int year, int month, int day, int hour, int minute, int second, | 192 /// For example, invoked with argument `2600` returns `3`. |
176 int millisecond, bool isUtc) { | 193 static int _microsecondInRoundedMilliseconds(int microsecond) { |
177 return Primitives.valueFromDecomposedDate( | 194 return (microsecond / 1000).round(); |
178 year, month, day, hour, minute, second, millisecond, isUtc); | |
179 } | 195 } |
180 | 196 |
181 @patch | 197 @patch |
| 198 static int _brokenDownDateToValue( |
| 199 int year, int month, int day, int hour, int minute, int second, |
| 200 int millisecond, int microsecond, bool isUtc) { |
| 201 return Primitives.valueFromDecomposedDate( |
| 202 year, month, day, hour, minute, second, |
| 203 millisecond + _microsecondInRoundedMilliseconds(microsecond), |
| 204 isUtc); |
| 205 } |
| 206 |
| 207 @patch |
182 String get timeZoneName { | 208 String get timeZoneName { |
183 if (isUtc) return "UTC"; | 209 if (isUtc) return "UTC"; |
184 return Primitives.getTimeZoneName(this); | 210 return Primitives.getTimeZoneName(this); |
185 } | 211 } |
186 | 212 |
187 @patch | 213 @patch |
188 Duration get timeZoneOffset { | 214 Duration get timeZoneOffset { |
189 if (isUtc) return new Duration(); | 215 if (isUtc) return new Duration(); |
190 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); | 216 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); |
191 } | 217 } |
192 | 218 |
193 @patch | 219 @patch |
| 220 DateTime add(Duration duration) { |
| 221 return new DateTime._withValue( |
| 222 _value + duration.inMilliseconds, isUtc: isUtc); |
| 223 } |
| 224 |
| 225 @patch |
| 226 DateTime subtract(Duration duration) { |
| 227 return new DateTime._withValue( |
| 228 _value - duration.inMilliseconds, isUtc: isUtc); |
| 229 } |
| 230 |
| 231 @patch |
| 232 Duration difference(DateTime other) { |
| 233 return new Duration(milliseconds: _value - other._value); |
| 234 } |
| 235 |
| 236 @patch |
| 237 int get millisecondsSinceEpoch => _value; |
| 238 |
| 239 @patch |
| 240 int get microsecondsSinceEpoch => _value * 1000; |
| 241 |
| 242 @patch |
194 int get year => Primitives.getYear(this); | 243 int get year => Primitives.getYear(this); |
195 | 244 |
196 @patch | 245 @patch |
197 int get month => Primitives.getMonth(this); | 246 int get month => Primitives.getMonth(this); |
198 | 247 |
199 @patch | 248 @patch |
200 int get day => Primitives.getDay(this); | 249 int get day => Primitives.getDay(this); |
201 | 250 |
202 @patch | 251 @patch |
203 int get hour => Primitives.getHours(this); | 252 int get hour => Primitives.getHours(this); |
204 | 253 |
205 @patch | 254 @patch |
206 int get minute => Primitives.getMinutes(this); | 255 int get minute => Primitives.getMinutes(this); |
207 | 256 |
208 @patch | 257 @patch |
209 int get second => Primitives.getSeconds(this); | 258 int get second => Primitives.getSeconds(this); |
210 | 259 |
211 @patch | 260 @patch |
212 int get millisecond => Primitives.getMilliseconds(this); | 261 int get millisecond => Primitives.getMilliseconds(this); |
213 | 262 |
214 @patch | 263 @patch |
| 264 int get microsecond => 0; |
| 265 |
| 266 @patch |
215 int get weekday => Primitives.getWeekday(this); | 267 int get weekday => Primitives.getWeekday(this); |
216 } | 268 } |
217 | 269 |
218 | 270 |
219 // Patch for Stopwatch implementation. | 271 // Patch for Stopwatch implementation. |
220 @patch | 272 @patch |
221 class Stopwatch { | 273 class Stopwatch { |
222 @patch | 274 @patch |
223 static void _initTicker() { | 275 static void _initTicker() { |
224 Primitives.initTicker(); | 276 Primitives.initTicker(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 return makeFixedListUnmodifiable/*<E>*/(result); | 327 return makeFixedListUnmodifiable/*<E>*/(result); |
276 } | 328 } |
277 } | 329 } |
278 | 330 |
279 @patch | 331 @patch |
280 class Map<K, V> { | 332 class Map<K, V> { |
281 @patch | 333 @patch |
282 factory Map.unmodifiable(Map other) { | 334 factory Map.unmodifiable(Map other) { |
283 return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other)); | 335 return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other)); |
284 } | 336 } |
| 337 |
| 338 @patch |
| 339 factory Map() = JsLinkedHashMap<K, V>.es6; |
285 } | 340 } |
286 | 341 |
287 @patch | 342 @patch |
288 class String { | 343 class String { |
289 @patch | 344 @patch |
290 factory String.fromCharCodes(Iterable<int> charCodes, | 345 factory String.fromCharCodes(Iterable<int> charCodes, |
291 [int start = 0, int end]) { | 346 [int start = 0, int end]) { |
292 if (charCodes is JSArray) { | 347 if (charCodes is JSArray) { |
293 return _stringFromJSArray(charCodes, start, end); | 348 return _stringFromJSArray(charCodes, start, end); |
294 } | 349 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return getTraceFromException(error); | 569 return getTraceFromException(error); |
515 } | 570 } |
516 // Fallback if Error.captureStackTrace does not exist. | 571 // Fallback if Error.captureStackTrace does not exist. |
517 try { | 572 try { |
518 throw ''; | 573 throw ''; |
519 } catch (_, stackTrace) { | 574 } catch (_, stackTrace) { |
520 return stackTrace; | 575 return stackTrace; |
521 } | 576 } |
522 } | 577 } |
523 } | 578 } |
OLD | NEW |