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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 598993002: Add missing null-tests to async error functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
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 part of dart.async; 5 part of dart.async;
6 6
7 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
(...skipping 18 matching lines...) Expand all
29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); 29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
30 typedef Timer CreatePeriodicTimerHandler( 30 typedef Timer CreatePeriodicTimerHandler(
31 Zone self, ZoneDelegate parent, Zone zone, 31 Zone self, ZoneDelegate parent, Zone zone,
32 Duration period, void f(Timer timer)); 32 Duration period, void f(Timer timer));
33 typedef void PrintHandler( 33 typedef void PrintHandler(
34 Zone self, ZoneDelegate parent, Zone zone, String line); 34 Zone self, ZoneDelegate parent, Zone zone, String line);
35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, 35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
36 ZoneSpecification specification, 36 ZoneSpecification specification,
37 Map zoneValues); 37 Map zoneValues);
38 38
39 /// Pair of error and stack trace. Returned by [Zone.errorCallback]. 39 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */
40 class AsyncError implements Error { 40 class AsyncError implements Error {
41 final error; 41 final error;
42 final StackTrace stackTrace; 42 final StackTrace stackTrace;
43 43
44 AsyncError(this.error, this.stackTrace); 44 AsyncError(this.error, this.stackTrace) {
45 if (error == null) throw new ArgumentError("Error must not be null");
floitsch 2014/09/24 12:59:14 Or make it a NullThrownError?
46 }
47
45 String toString() => error.toString(); 48 String toString() => error.toString();
46 } 49 }
47 50
48 51
49 class _ZoneFunction { 52 class _ZoneFunction {
50 final _Zone zone; 53 final _Zone zone;
51 final Function function; 54 final Function function;
52 const _ZoneFunction(this.zone, this.function); 55 const _ZoneFunction(this.zone, this.function);
53 } 56 }
54 57
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 /** 250 /**
248 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous 251 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous
249 * callbacks are executed in the zone they have been queued in. For example, 252 * callbacks are executed in the zone they have been queued in. For example,
250 * the callback of a `future.then` is executed in the same zone as the one where 253 * the callback of a `future.then` is executed in the same zone as the one where
251 * the `then` was invoked. 254 * the `then` was invoked.
252 */ 255 */
253 abstract class Zone { 256 abstract class Zone {
254 // Private constructor so that it is not possible instantiate a Zone class. 257 // Private constructor so that it is not possible instantiate a Zone class.
255 Zone._(); 258 Zone._();
256 259
257 /// The root zone that is implicitly created. 260 /** The root zone that is implicitly created. */
floitsch 2014/09/24 12:59:14 why this change?
Lasse Reichstein Nielsen 2014/09/24 13:49:57 Just because the comment style was inconsistent wi
258 static const Zone ROOT = _ROOT_ZONE; 261 static const Zone ROOT = _ROOT_ZONE;
259 262
260 /// The currently running zone. 263 /** The currently running zone. */
261 static Zone _current = _ROOT_ZONE; 264 static Zone _current = _ROOT_ZONE;
262 265
263 static Zone get current => _current; 266 static Zone get current => _current;
264 267
265 dynamic handleUncaughtError(error, StackTrace stackTrace); 268 dynamic handleUncaughtError(error, StackTrace stackTrace);
266 269
267 /** 270 /**
268 * Returns the parent zone. 271 * Returns the parent zone.
269 * 272 *
270 * Returns `null` if `this` is the [ROOT] zone. 273 * Returns `null` if `this` is the [ROOT] zone.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 * or [Future] constructors that take an error or a callback that may throw, 412 * or [Future] constructors that take an error or a callback that may throw,
410 * the current zone is allowed to intercept and replace the error. 413 * the current zone is allowed to intercept and replace the error.
411 * 414 *
412 * When other libraries use intermediate controllers or completers, such 415 * When other libraries use intermediate controllers or completers, such
413 * calls may contain errors that have already been processed. 416 * calls may contain errors that have already been processed.
414 * 417 *
415 * Return `null` if no replacement is desired. 418 * Return `null` if no replacement is desired.
416 * The original error is used unchanged in that case. 419 * The original error is used unchanged in that case.
417 * Otherwise return an instance of [AsyncError] holding 420 * Otherwise return an instance of [AsyncError] holding
418 * the new pair of error and stack trace. 421 * the new pair of error and stack trace.
422 *
423 * The returned [AsyncError.error] must not be `null`.
419 */ 424 */
420 AsyncError errorCallback(Object error, StackTrace stackTrace); 425 AsyncError errorCallback(Object error, StackTrace stackTrace);
421 426
422 /** 427 /**
423 * Runs [f] asynchronously in this zone. 428 * Runs [f] asynchronously in this zone.
424 */ 429 */
425 void scheduleMicrotask(void f()); 430 void scheduleMicrotask(void f());
426 431
427 /** 432 /**
428 * Creates a Timer where the callback is executed in this zone. 433 * Creates a Timer where the callback is executed in this zone.
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 handleUncaughtError: errorHandler); 1245 handleUncaughtError: errorHandler);
1241 } 1246 }
1242 Zone zone = Zone.current.fork(specification: zoneSpecification, 1247 Zone zone = Zone.current.fork(specification: zoneSpecification,
1243 zoneValues: zoneValues); 1248 zoneValues: zoneValues);
1244 if (onError != null) { 1249 if (onError != null) {
1245 return zone.runGuarded(body); 1250 return zone.runGuarded(body);
1246 } else { 1251 } else {
1247 return zone.run(body); 1252 return zone.run(body);
1248 } 1253 }
1249 } 1254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698